
package com.geelaro.register.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import com.geelaro.register.domain.entity.Employee;
import com.geelaro.register.repository.EmployeeRepository;
import com.geelaro.register.service.EmployeeService;


@Service
public class EmployeeServiceImpl implements EmployeeService {

	@Autowired
	private EmployeeRepository employeeRepository;

	// 查找所有员工
	@Override
	public List<Employee> findAll() {
		return employeeRepository.findAll();
	}

	@Override
	public void deleteById(Integer id) {
		employeeRepository.deleteById(id);
	}

	@Override
	public void save(Employee employee) {
		employeeRepository.save(employee);
	}

	/*
	 * @Override public Employee getEmployeeById(Integer id) { // TODO
	 * Auto-generated method stub return employeeRepository.getEmployeeById(id); }
	 */
	@Override
	public Employee findEmployeeById(Integer id) {
		// TODO Auto-generated method stub
		return employeeRepository.findEmployeeById(id);
	}

	@Override
	public Page<Employee> findAll(int pageNum, int pageSize) {
		Pageable pageable = PageRequest.of(pageNum, pageSize, Sort.by(Sort.Order.asc("id")));
		Page<Employee> employees = employeeRepository.findAll(pageable);
		return employees;
	}

}
